package com.jsle.financial.manager;


import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.jsle.financial.dao.ResourcesDao;
import com.jsle.financial.domain.Resources;
import com.jsle.financial.util.Constants;
import com.jsle.financial.vo.Result;

/**
 * Manager 用于事物控制
 * @author zhangyanqing
 * @date 2012-10-27
 */
public class ResourcesManagerImpl implements ResourcesManager{
	private Log log = LogFactory.getLog(ResourcesManagerImpl.class);
	
	@Resource
	private ResourcesDao resourcesDao;
	
	/**
	 * 新增一资源
	 * @param Resource
	 * @return
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=Exception.class)
	public Result addResource(Resources resource){
		Result result = new Result();
		try {
			result = resourcesDao.addResource(resource);
		} catch (Exception e) {
			result.setResultCode(Constants.Manager.FC_RESULT_INSERT_TRANSACTIONAL_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Manager.FC_RESULT_INSERT_TRANSACTIONAL_ERROR_MESSAGE, "Resource"));
			log.error("new Resource error## "+ e.getMessage());
		}
		return result;
	}
	/**
	 * 删除一资源
	 * @param Resource
	 * @return
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=Exception.class)
	public Result delResources(Resources resource){
		Result result = new Result();
		try {
			result = resourcesDao.delResources(resource);
		} catch (Exception e) {
			result.setResultCode(Constants.Manager.FC_RESULT_DEL_TRANSACTIONAL_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Manager.FC_RESULT_DEL_TRANSACTIONAL_ERROR_MESSAGE, "Resource"));
			log.error("del Resource error## "+ e.getMessage());
		}
		return result;
	}
	/**
	 * 更新一资源信息
	 * @param Resource
	 * @return
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor=Exception.class)
	public Result updateResource(Resources resource){
		Result result = new Result();
		try {
			result = resourcesDao.updateResource(resource);

		} catch (Exception e) {
			result.setResultCode(Constants.Manager.FC_RESULT_UPDATE_TRANSACTIONAL_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Manager.FC_RESULT_UPDATE_TRANSACTIONAL_ERROR_MESSAGE, "Resource"));
			log.error("update Resource error## "+ e.getMessage());
		}
		return result;
	}
	
}
